﻿package Classes.DisplayHelper {
	
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import flash.filters.GlowFilter;
	import flash.geom.*;
	
	import flash.display.MovieClip;

	import com.greensock.*;
	import com.greensock.easing.*;
	
	import Classes.BaseProperties;
	import Classes.Score.*;
	
	public class ScoreViewer extends TextField  {
		
		private var wolk:MovieClip;
		
		public function ScoreViewer(points:Number) { 
			
			var format:TextFormat = new TextFormat();

			if (points>=0) {

				this.text="+"+points;
				format.color=0x107200;

			} else {

				this.text="-"+points;
				format.color=0xFF0000;

			}

			this.width=75;

			var location:Point=new Point(mouseX,mouseY);
			location=this.localToGlobal(location);
			
			this.x=location.x-this.width/2;
			this.y=location.y;
			
			this.selectable=false;
			this.embedFonts=true;
			
			var font:Bauhaus = new Bauhaus();

			format.font=font.fontName;
			format.size=24;
			format.bold=true;
			format.align="center";
			this.setTextFormat(format);
			
			this.filters = [new GlowFilter(0xFFFFFF,1,5,5,2,2)]

			BaseProperties.activeStage.addChild(this);
			
			this.mouseEnabled=false;
			
			wolk = new mcWolkjes();
			wolk.x = location.x;
			wolk.y = location.y;
			
			wolk.mouseEnabled=false;
			
			BaseProperties.activeStage.addChild(wolk);
			
			TweenLite.to(this, 1, {x:7, y:26, alpha:0, ease:Back.easeIn, onComplete: animationEnd, onCompleteParams:[points]});
			TweenLite.to(wolk, 0.5, {y:wolk.y-15, alpha:0, ease:Back.easeIn});
			
		}
		
		public function animationEnd(points:Number){
			
			Keeper.getInstance().addScore(points);
			BaseProperties.scoreTextfield.text = Keeper.getInstance().getScore().toString();
			BaseProperties.activeStage.removeChild(this);
			BaseProperties.activeStage.removeChild(wolk);
			
		}
	

	}
	
}